package com.allianz.webapps.secondController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.frame.utils.MailUtil;

@Controller
public class AppCallBackController {

	/**
	 * 图片base64 发至统一邮箱
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/index/report/upImgFile")
	@ResponseBody
	public Object callBack(HttpServletRequest request,HttpSession session){
		Map<String,Object> map = new HashMap<String, Object>();
		String images = request.getParameter("images");//这个就是前端传来的base64图片数据
		//问题截图
		List<String>  imagList = Arrays.asList(images.split(","));
		//问题类型
		String reportType=request.getParameter("reportType");
		//问题描述
		String reportDescribe=request.getParameter("describe");
		boolean flag = false;
		try {
			//发送反馈邮件
			flag = MailUtil.sendEmail(reportDescribe, imagList, reportType);
		if (!flag) {
			//失败重新发一次
				MailUtil.sendEmail(reportDescribe, imagList, reportType);
				flag = true;
		}
		map.put("status", "success");
		map.put("msg", "反馈信息已发至相关负责人邮箱!");
		} catch (Exception e) {
			e.printStackTrace();
			map.put("status", "error");
			map.put("msg", "反馈信息发送失败,请联系管理人员!");
		}
		return map;
	}
}
